package com.eshop.product.controller;

import com.eshop.product.model.Brand;
import com.eshop.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CategoryController
 * @Description
 * @Author 47980
 * @Date 2020/5/17 16:18
 * @Version V_1.0
 **/
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/add")
    public String add (Brand brand, String operationType) {
        try {
            brandService.add(brand, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";

    }

    @GetMapping("/update")
    public String update (Brand brand, String operationType) {
        try {
            brandService.update(brand, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/delete")
    public String delete (Long id, String operationType) {
        try {
            brandService.delete(id, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/findById")
    public Brand findById (Long id) {
        return brandService.findById(id);
    }

    @GetMapping("/findByIds")
    public List<Brand> findByIds (String ids) {
        return brandService.findByIds(ids);
    }
}
